import React, { Component } from "react";
import { connect } from "react-redux";
import MainLayout from "../../../../component/mainLayout/mainLayout";
import "./RechargeSuccess.scss";
import { dropByCacheKey } from "react-router-cache-route";

class RechargeSuccess extends Component {
	constructor(props) {
		super(props);
		this.state = {};
		this._pagetype = props.location.pathname.indexOf("xhb") === -1 ? 0 : 1;
	}

	componentDidMount() {
		dropByCacheKey("transferXHBInto");
	}

	render() {
		const headerParams = {
			header: {
				title: "充值结果",
				goBackPath: "/walletHome"
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles,
			loadStatus: this.state.loadStatus // （ '0'：数据加载中，'1'：加载完成，'2'：加载失败）
		};
		return (
			<MainLayout pageParams={headerParams}>
				<div className="recharge-success-page">
					<div className="top-content">
						<img
							className="top-img"
							src={require("../../../../images/icon/ok.png")}
						/>
						<div className="tips">充值成功</div>
						<div className="line-2">
							<div className="item">
								<div className="item-top">充值金额</div>
								<div className="item-bottom">
									¥{this.props.match.params.amount}
								</div>
							</div>
							<div className="item">
								<div className="item-top">账户金额</div>
								<div className="item-bottom">
									¥{this.props.match.params.eleAmout}
								</div>
							</div>
						</div>
						<div className="t-type">
							<div className="t-left">付款方式</div>
							<div className="t-right">
								{this.props.match.params.cardName}（
								{this.props.match.params.cardNo}）
							</div>
						</div>
					</div>
					<div className="line-3">
						{/*<div className="item t-b" onClick={this.gotoNext.bind(this, 1)}>回到首页</div>*/}
						<div className="item t-w" onClick={this.gotoNext.bind(this, 2)}>
							立即购买小辉宝
						</div>
					</div>
				</div>
			</MainLayout>
		);
	}
	gotoNext(i) {
		if (i === 1) {
			//转出
			this.props.history.push({
				pathname: `/walletHome`
			});
		} else if (i === 2) {
			//转入
			let obj = JSON.parse(sessionStorage.getItem("walletHomeData"));
			this.props.history.push({
				pathname: `/transferXHBInto/${obj.productId || ""}`,
				params: {}
			});
		}
	}
}

function mapStateToProps(state) {
	return state;
}

function mapDispatchToProps() {
	return {};
}

export default connect(mapStateToProps, mapDispatchToProps)(RechargeSuccess);
